/**   
* @Title: Swagger2.java 
* @Package org.ay.ispringboot 
* @Description: TODO(用一句话描述该文件做什么) 
* @author AndyLi   
* @date Jan 26, 2018 10:56:15 AM 
* @version V1.0   
*/
package org.ay.ispringboot;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author AndyLi
 *
 */
@Configuration
@EnableSwagger2
public class Swagger2 {
	
	@Bean
	public Docket createDocket() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(createApiInfo())
				.select()
				//select()函数返回一个ApiSelectorBuilder实例用来控制哪些接口暴露给Swagger来展现，本例采用指定扫描的包路径来定义
				//，Swagger会扫描该包下所有Controller定义的API，并产生文档内容（除了被@ApiIgnore指定的请求）
				.apis(RequestHandlerSelectors.basePackage("org.ay.ispringboot.web.controller"))
				.paths(PathSelectors.any())
				.build();
	}

	private ApiInfo createApiInfo() {
		return  new ApiInfoBuilder()
				.title("iSpringBoot web restful API")
				.description("系统对外接口")
				.termsOfServiceUrl("http://google.com")
				.contact("andyli")
				.version("0.0.1")
				.build();
	}
}
